<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/commons/taglibs.jsp"%>
<%@ include file="/static/commons/meta.jsp"%>
<%@ include file="/static/commons/jquery-easyui.jsp"%>
<html >
	 <head>
 		<title>${title }</title>
 		 <link rel="stylesheet" href="${ctx }/static/styles/basic/basic.css" />
		 <link rel="stylesheet" href="${ctx }/static/styles/frame/main.css" />
		 <link rel="stylesheet" href="${ctx }/static/styles/frame/searchBtn.css" />
		 <link rel="stylesheet" href="${ctx }/static/styles/frame/searchCondition.css" />
	 
 		<script language="JavaScript" src="${ctx}/static/scripts/check_all.js"></script>
 		<script language="JavaScript" src="${ctx}/static/scripts/set_select.js"></script>
 		<script language="JavaScript" src="${ctx}/static/scripts/waiting.js"></script>
 		<script language="JavaScript" src="${ctx}/static/scripts/crud.js"></script>
 		<script language="JavaScript" src="${ctx}/static/scripts/util.js"></script>
  </head>
  
  <body onload="init()">
  		<form action="${ctx}/dept/list" method="post">
  			<input type="hidden" name="RequestVerificationToken" value="${RequestVerificationToken}" />
           <div class="width_100 group_box">
				<div class="group_search width_100">
					<vvise:select ifTree="true" id="deptId" name="p_deptId" sqlname="getDeptByUser" sqlparam="${LoginUser.deptId}" displayText="上级部门" ifSearch="true"   />
					<vvise:select id="status" name="p_status" sqlname="getCodeData" sqlparam="data_status" displayText="状态" ifSearch="true"   />
					<vvise:searchInput id="deptName" name="p_deptName" displayText="部门名称" />
               	 	<div class="clear_both"></div>
				</div>
				<vvise:funMenu menuId="${menuId}" />
			</div>
        </form>
        <div class="listFrame">
        	<iframe name="listFrame" id="listFrame" frameBorder="0"
				scrolling="auto" style="width: 100%;height:100%;"></iframe>
        </div>
  </body>
  <script type="text/javascript">
  		var headers = {};
		headers['__RequestVerificationToken'] = "${RequestVerificationToken}";
		//回车事件
		document.onkeydown = keyKistener;
		function keyKistener(e){
			e = e ? e:event;
			if(e.keyCode == 13){
				try{
					search();
				}catch(e){}
			}
		}
		function init(){
			set_iframe_h();
			$(window).resize(function(){
				set_iframe_h();
			});
			search();
			$('.easyui-combobox').combobox();
		}
		//设置ifream 高度
		function set_iframe_h(){
			var win_height  = $(window).height();
			var func_line_h = $('.group_box').outerHeight(true);
			var list_height = win_height - func_line_h;
			$('.listFrame').css('height',list_height-10);
		}
		function search(){
			waiting();
			document.forms[0].target = "listFrame";
			document.forms[0].submit();
		}
		
		function create(deptId){
			var pp = parent;
			if(pp.isEmpty(deptId)){
				deptId = "";
			}
			doCreate("部门信息",pp.width1,290,"${ctx}/dept/edit?p_deptId="+deptId);
		}
		function save(){
			var pp = parent;
			var editFrame = pp.winFrame;
			var id = editFrame.$('#deptId').val();
			var pDeptId= editFrame.$('#pDeptId').val();
			var deptName = editFrame.$('#deptName').val();
			var deptName_ = editFrame.$('#deptName_').val();
			
			if(!pp.validData("pDeptId","请选择上级部门！",3))
			return;
			
			if(!pp.validData("deptName","请输入部门名称！"))
				return;
		 	if(deptName.length>50){
		 		pp.$.messager.alert('操作提示',"部门名称不能超过50字！","info",function(){
					editFrame.$('#deptName').focus();
				});
	   		   	return;
		 	}
	  	 	var flag = executeAjaxBySync('${ctx}/dept/checkName','p_deptId='+id+"&p_deptName="+deptName);
			if(flag == 'ERROR'){
				pp.alertMsg('部门已存在，请重新输入！','warning',function(){
					try{
					 	editFrame.$('#deptName').focus();
				 	 }catch(e){}
				});
				return;
			}
			
			doSave("${ctx}/dept/save",id);
		}
		
		function view(deptId){
			var pp = parent;
			doView("部门信息",pp.width2-300,290,"${ctx}/dept/edit?p_deptId="+deptId+"&view=view");
		}
		function updateStatus(flag){
			var pp = parent;
			var ids = "";
			var ecForm = listFrame.document.all.ec;
			if(!checkSelect(ecForm.id,true))
				return;
			ids = get_checkbox_values(ecForm.id,',');
			
			var optMsg = "状态修改成功！";
			var msgVal = "启用";
			if(flag == 2)
				msgVal = "停用";
			if(flag == 3){
				msgVal = "删除";
				optMsg = "删除成功！";
			}
			pp.confirmMsg("确定要"+ msgVal +"吗？",function(){
				var urls = "${ctx}/dept/updateStatus";
			    var params = "ids="+ids;
			    params += "&status="+flag;
			    executeAjax(urls,params,function(data){
				    if(data == 'success'){
				    	pp.$.messager.alert('操作提示', optMsg, "info",function(){
				    		listRefresh();
				    	});
					}else{
						pp.$.messager.alert('操作提示',"操作失败！","error");
					}
			    });
			});
		}
	</script>
</html>